package nc.bs.arap.util;

import nc.bs.pfxx.ITranslateContext;
import nc.bs.pfxx.ITranslatorStrategy;
import nc.pubitf.bd.accessor.GeneralAccessorFactory;
import nc.pubitf.bd.accessor.IGeneralAccessor;
import nc.vo.bd.accessor.IBDData;
import nc.vo.pfxx.exception.PfxxException;
import nc.vo.pfxx.xxconfig.IBasicDataMatchRule;

public class NCTranslator implements ITranslatorStrategy {

	@Override
	public String translateExToNC(String srcValue, String metaDataID,
			ITranslateContext translateContext) throws PfxxException {
		if (translateContext.getTranslateRule() == IBasicDataMatchRule.RULE_PK) {
			return srcValue;
		}
		IGeneralAccessor accessor = GeneralAccessorFactory
				.getAccessor(metaDataID);
		IBDData doc = null;
		if (translateContext.getTranslateRule() == IBasicDataMatchRule.RULE_CODE) {
			doc = accessor.getDocByCode(translateContext.getOrgPk(), srcValue);
		} else if (translateContext.getTranslateRule() == IBasicDataMatchRule.RULE_NAME) {
			doc = accessor.getDocByNameWithMainLang(translateContext.getOrgPk(), srcValue);
		}
		if (doc != null)
			return doc.getPk();
		return null;
	}

	@Override
	public String translateNCToEx(String docPk, String metaDataID,
			ITranslateContext translateContext) throws PfxxException {
		return null;
	}

	@Override
	public String getStrategyDescription() {
		return null;
	}
}
